package common.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
 * 字符串工具类
 * 
 * @author dwen
 * @date 2018年3月15日上午11:13:06
 * @version v1.0
 */
public class StringUtils {

	/** 日志 */
	private static final Logger LOGGER = LoggerFactory.getLogger(StringUtils.class);

	/**
	 * 判断字符串是否包含有意义字符
	 * 
	 * <pre>
	 * StringUtils.hasText(&quot; &quot;) = false;
	 * StringUtils.hasText(&quot;test&quot;) = true;
	 * StringUtils.hasText(null) = false;
	 * StringUtils.hasText(&quot;  test&quot;) = true;
	 * </pre>
	 * 
	 * @param str
	 * @return true/false
	 */
	public static boolean hasText(String str) {
		if (!hasLength(str)) {
			return false;
		}
		int strLen = str.length();
		for (int i = 0; i < strLen; i++) {
			if (!Character.isWhitespace(str.charAt(i))) {
				return true;
			}
		}
		return false;
	}

	/**
	 * 判断字符串是否为空或null(去除空格)
	 * 
	 * <pre>
	 * StringUtils.emptyOrNull(&quot; &quot;) = true;
	 * StringUtils.emptyOrNull(null) = true;
	 * StringUtils.emptyOrNull(&quot;test&quot;) = false;
	 * StringUtils.emptyOrNull(&quot; test&quot;) = false;
	 * </pre>
	 * 
	 * @param str
	 * @return
	 */
	public static boolean emptyOrNull(String str) {
		return str == null || !hasText(str);
	}

	/**
	 * 判断字符串是否有长度
	 * 
	 * <pre>
	 * StringUtils.hasLength(&quot; &quot;) = true;
	 * StringUtils.hasLength(&quot;&quot;) = false;
	 * StringUtils.hasLength(&quot;abc&quot;) = true;
	 * StringUtils.hasLength(null) = false;
	 * </pre>
	 * 
	 * @param str
	 * @return
	 */
	public static boolean hasLength(String str) {
		return str != null && str.length() > 0;
	}

	/**
	 * 日期转字符串(yyyy-MM-dd HH:mm:ss)
	 * 
	 * <pre>
	 * StringUtils.dateToString(new Date()) = &quot;2011-06-13 14:00:00&quot;
	 * </pre>
	 * 
	 * @param date
	 * @return String(yyyy-MM-dd HH:mm:ss)
	 */
	public static synchronized String dateToString(Date date) {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return format.format(date);
	}

	public static synchronized String dateToStringShort(Date date) {
		SimpleDateFormat shortFormat = new SimpleDateFormat("yyyy-MM-dd");
		return shortFormat.format(date);
	}

	/**
	 * 格式数字
	 * 
	 * <pre>
	 * StringUtils.formatNumber(new Long(100000)) = 100,000.00
	 * StringUtils.formatNumber(new Double(100000)) = 100,000.00
	 * StringUtils.formatNumber(new Integer(100000)) = 100,000.00
	 * StringUtils.formatNumber(new Float(100000)) = 100,000.00
	 * StringUtils.formatNumber(new Long(1)) = 1.00
	 * StringUtils.formatNumber(new Long(111)) = 111.00
	 * StringUtils.formatNumber(new Long(1111)) = 1,111.00
	 * </pre>
	 * 
	 * @param num
	 *            数字
	 * @return 格式化数字字符串
	 */
	public static String formatNumber(Number num) {
		String fmtString = null;
		try {
			DecimalFormat numberFormat = new DecimalFormat("###,###.##");
			fmtString = numberFormat.format(num);
		} catch (IllegalArgumentException e) {
			throw e;
		}
		return fmtString;
	}

	/**
	 * 根据数字格式,格式化数字
	 * 
	 * <pre>
	 * StringUtils.formatNumber(new Long(1000),"##,###.00") = 1,000.00
	 * StringUtils.formatNumber(new Long(100000),"#,####.00") = 10,0000.00
	 * </pre>
	 * 
	 * @param num
	 *            数字
	 * @param fmtString
	 *            格式串
	 * @return
	 */
	public static String formatNumber(Number num, String fmtString) {
		DecimalFormat customerFormat = new DecimalFormat(fmtString);
		fmtString = customerFormat.format(num);
		return fmtString;
	}

	/**
	 * 数字字符串转数字
	 * 
	 * <pre>
	 * StringUtils.parseNumber(&quot;100&quot;) = 100;
	 * </pre>
	 * 
	 * @param numberString
	 *            数字字符串
	 * @return Number
	 * @throws ParseException
	 */
	public static Number parseNumber(String numberString) {
		Number number = null;
		try {
			DecimalFormat numberFormat = new DecimalFormat("###,###.##");
			number = numberFormat.parse(numberString);
		} catch (ParseException e) {
			throw new IllegalArgumentException(numberString + " is not a number format!");
		}
		return number;
	}

	/**
	 * 全角转半角
	 * 
	 * @param input
	 * @return
	 */
	public static String toDBC(String input) {
		char[] c = input.toCharArray();
		for (int i = 0; i < c.length; i++) {
			if (c[i] == 12288) {
				c[i] = (char) 32;
				continue;
			}
			if (c[i] > 65280 && c[i] < 65375)
				c[i] = (char) (c[i] - 65248);
		}
		return new String(c);
	}

	/**
	 * 字符串转int
	 * 
	 * @param input
	 * @return
	 */
	public static Integer parseInt(String input, Integer defaultVal) {
		try {
			if (!StringUtils.hasText(input)) {
				return defaultVal;
			}
			if (Pattern.matches("(^\\d+(\\.\\d+)?$|^\\d+(\\,\\d+)+(\\.\\d+)?$)", input)) {
				input = input.replaceAll(",", "");
				return Double.valueOf(input).intValue();
			}
		} catch (NumberFormatException e) {
			LOGGER.error("parse Long error![input=" + input + "] :", e.getMessage());
			return defaultVal;
		}
		return defaultVal;
	}

	/**
	 * 处理整型字符串
	 * 
	 * <pre>
	 * StringUtils.treatInt("000900") =  "900"
	 * StringUtils.treatInt("900") = "900"
	 * </pre>
	 * 
	 * @param str
	 * @return
	 */
	public static String treatInt(String str) {
		int result = 0;
		if (null == str) {
			return null;
		}
		for (int i = 0; i < str.length(); i++) {
			if (str.charAt(i) >= '0' && str.charAt(i) <= '9') {
				result = result * 10 + str.charAt(i) - 48;
			}
		}
		return String.valueOf(result);
	}

	/**
	 * 字符串转long
	 * 
	 * @param input
	 * @return
	 */
	public static Long parseLong(String input) {
		try {
			if (!StringUtils.hasText(input)) {
				return Long.MIN_VALUE;
			}
			if (Pattern.matches("(^\\d+(\\.\\d+)?$|^\\d+(\\,\\d+)+(\\.\\d+)?$)", input)) {
				input = input.replaceAll(",", "");
				return Long.valueOf(input);
			}
		} catch (NumberFormatException e) {
			LOGGER.error("parse Long error![input=" + input + "] :", e.getMessage());
			return Long.MIN_VALUE;
		}
		return Long.MIN_VALUE;
	}

	/**
	 * 字符串转Long型
	 * 
	 * @param input
	 * @param defaultVal
	 * @return
	 */
	public static Long parseLong(String input, Long defaultVal) {
		try {
			if (!StringUtils.hasText(input)) {
				return defaultVal;
			}
			if (Pattern.matches("(^\\d+(\\.\\d+)?$|^\\d+(\\,\\d+)+(\\.\\d+)?$)", input)) {
				input = input.replaceAll(",", "");
				return Long.valueOf(input);
			}
		} catch (NumberFormatException e) {
			LOGGER.error("parse Long error![input=" + input + "] :", e.getMessage());
			return defaultVal;
		}
		return defaultVal;
	}

	public static Double parseDouble(String input) {
		try {
			if (!StringUtils.hasText(input)) {
				return Double.MIN_VALUE;
			}
			if (Pattern.matches("(^\\d+(\\.\\d+)?$|^\\d+(\\,\\d+)+(\\.\\d+)?$)", input)) {
				input = input.replaceAll(",", "");
				return Double.valueOf(input);
			}
		} catch (NumberFormatException e) {
			LOGGER.error("parse Long error![input=" + input + "] :", e.getMessage());
			return Double.MIN_VALUE;
		}
		return Double.MIN_VALUE;
	}

	public static Double parseDouble(String input, Double defaultVal) {
		try {
			if (!StringUtils.hasText(input)) {
				return defaultVal;
			}
			if (Pattern.matches("(^\\d+(\\.\\d+)?$|^\\d+(\\,\\d+)+(\\.\\d+)?$)", input)) {
				input = input.replaceAll(",", "");
				return Double.valueOf(input);
			}
		} catch (NumberFormatException e) {
			LOGGER.error("parse Long error![input=" + input + "] :", e.getMessage());
			return defaultVal;
		}
		return defaultVal;
	}

	/**
	 * 
	 * 空字符串处理
	 * 
	 * <pre>
	 * StringUtils.dealNull(new Integer(2),"0") = 2
	 * StringUtils.dealNull(null,"0") = 0
	 * </pre>
	 * 
	 * @param str
	 * @param defaultValue
	 * @return
	 */
	public static String dealNull(Object str, String defaultValue) {
		return null != str ? str.toString() : defaultValue;
	}

	/**
	 * 检查字符串是否不是空白：<code>null</code>、空字符串<code>""</code>或只有空白字符。
	 * 
	 * <pre>
	 * StringUtil.isBlank(null)      = false
	 * StringUtil.isBlank("")        = false
	 * StringUtil.isBlank(" ")       = false
	 * StringUtil.isBlank("bob")     = true
	 * StringUtil.isBlank("  bob  ") = true
	 * </pre>
	 *
	 * @param str
	 *            要检查的字符串
	 *
	 * @return 如果为空白, 则返回<code>false</code>
	 */
	public static boolean isNotBlank(String str) {
		return org.apache.commons.lang3.StringUtils.isNotBlank(str);
	}

	/**
	 * 生成订单号 格式：年月日时分秒+随机三位数字
	 * 
	 * @return
	 */
	public static String getOrderNo() {
		return new SimpleDateFormat("yyyyMMddHHmmss").format(Calendar.getInstance().getTime())
				+ String.valueOf((int) (Math.random() * 900) + 100);
	}

	/**
	 * 待特殊字符的unicodeStr转中文
	 * ref:http://wx-xw.iteye.com/blog/1508986
	 * @param unicodeStr
	 * @return
	 */
	public static String unicodeEsc2Unicode(String unicodeStr) {
		if (unicodeStr == null) {
			return null;
		}
		StringBuffer retBuf = new StringBuffer();
		int maxLoop = unicodeStr.length();
		for (int i = 0; i < maxLoop; i++) {
			if (unicodeStr.charAt(i) == '\\') {
				if ((i < maxLoop - 5) && ((unicodeStr.charAt(i + 1) == 'u') || (unicodeStr.charAt(i + 1) == 'U')))
					try {
						retBuf.append((char) Integer.parseInt(unicodeStr.substring(i + 2, i + 6), 16));
						i += 5;
					} catch (NumberFormatException localNumberFormatException) {
						retBuf.append(unicodeStr.charAt(i));
					}
				else
					retBuf.append(unicodeStr.charAt(i));
			} else {
				retBuf.append(unicodeStr.charAt(i));
			}
		}

		return retBuf.toString();
	}

	public static String toBinary(String str){
		//把字符串转成字符数组
		char[] strChar=str.toCharArray();
		String result="";
		for(int i=0;i<strChar.length;i++){
			//toBinaryString(int i)返回变量的二进制表示的字符串
			//toHexString(int i) 八进制
			//toOctalString(int i) 十六进制
			result +=Integer.toBinaryString(strChar[i])+ " ";
		}
		return result;
	}

	/***
	 * 判空设置为0
	 * @param str
	 * @return
	 */
	public static int strToInt(String str){
		if(StringUtils.isNotBlank(str)){
			return Integer.parseInt(str);
		}
		return 0;
	}
	

	/***
	 * 判空设置为0
	 * @param str
	 * @return
	 */
	public static long strToLong(String str){
		if(StringUtils.isNotBlank(str)){
			return Long.parseLong(str);
		}
		return 0l;
	}


	/**
	 * 提取字符串中的手机号
	 * @param sParam
	 * @return
	 */

	public static String getTelnum(String sParam){

		if (!isNotBlank(sParam) && sParam == null) {
			return "";
		}

		if(sParam.length()<=0)
			return "";
		Pattern pattern = Pattern.compile("(1|861)(3|5|8)\\d{9}$*");
		Matcher matcher = pattern.matcher(sParam);
		StringBuffer bf = new StringBuffer();
		while (matcher.find()) {
			bf.append(matcher.group()).append(",");
		}
		int len = bf.length();
		if (len > 0) {
			bf.deleteCharAt(len - 1);
		}
		return bf.toString();
	}

	/**
	 * 解析地址
	 * @param address
	 * @return
	 */
	public static List<Map<String,String>> addressResolution(String address) {
		/*
		 * java.util.regex是一个用正则表达式所订制的模式来对字符串进行匹配工作的类库包。它包括两个类：Pattern和Matcher Pattern
		 *    一个Pattern是一个正则表达式经编译后的表现模式。 Matcher
		 *    一个Matcher对象是一个状态机器，它依据Pattern对象做为匹配模式对字符串展开匹配检查。
		 *    首先一个Pattern实例订制了一个所用语法与PERL的类似的正则表达式经编译后的模式，然后一个Matcher实例在这个给定的Pattern实例的模式控制下进行字符串的匹配工作。
		 */
		String regex = "(?<province>[^省]+自治区|.*?省|.*?行政区|.*?市)(?<city>[^市]+自治州|.*?地区|.*?行政单位|.+盟|市辖区|.*?市|.*?县)(?<county>[^县]+县|.+区|.+市|.+旗|.+海域|.+岛)?(?<town>[^区]+区|.+镇)?(?<village>.*)";
		Matcher m = Pattern.compile(regex).matcher(address);
		String province = null, city = null, county = null, town = null, village = null;
		List<Map<String, String>> table = new ArrayList<Map<String, String>>();
		Map<String, String> row = null;
		while (m.find()) {
			row = new LinkedHashMap<String, String>();
			province = m.group("province");
			row.put("province", province == null ? "" : province.trim());
			city = m.group("city");
			row.put("city", city == null ? "" : city.trim());
			county = m.group("county");
			row.put("county", county == null ? "" : county.trim());
			town = m.group("town");
			row.put("town", town == null ? "" : town.trim());
			village = m.group("village");
			row.put("village", village == null ? "" : village.trim());
			table.add(row);
		}
		return table;
	}

	public static String getJsSdkSign(String noncestr,String tsapiTicket,String timestamp,String url){
		String content="jsapi_ticket="+tsapiTicket+"&noncestr="+noncestr+"&timestamp="+timestamp+"&url="+url;
		String ciphertext=null;
		try {
			MessageDigest md = MessageDigest.getInstance("SHA-1");
			byte[] digest = md.digest(content.toString().getBytes());
			ciphertext=byteToStr(digest);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return ciphertext;
	}
	public static String byteToStr(byte[] byteArray){
		String strDigest="";
		for (int i = 0; i < byteArray.length; i++) {
			strDigest+=byteToHexStr(byteArray[i]);
		}
		return strDigest;
	}
	public static String byteToHexStr(byte mByte){
		char[] Digit={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
		char[] tempArr = new char[2];
		tempArr[0]=Digit[(mByte>>>4)&0X0F];
		tempArr[1]=Digit[mByte&0X0F];
		String s=new String(tempArr);
		return s;
	}
	public static String areaCode2(String province) {
		String[] str = {"29","512","851","931","28","27","10","431","21","951","731","551","971","471","311","791","24","756","591","771","451","898","871","371","571","351"};
		Random random = new Random();
		int n = random.nextInt(str.length);
		String areaCode = str[n];
		switch (province) {
			case "陕西省" :
				areaCode = "西安";
				break;
			case "江苏省" :
				areaCode = "南京";
				break;
			case "贵州省" :
				areaCode = "贵阳";
				break;
			case "甘肃省" :
				areaCode = "兰州";
				break;
			case "四川省" :
				areaCode = "成都";
				break;
			case "湖北省" :
				areaCode = "武汉";
				break;
			case "北京" :
				areaCode = "北京";
				break;
			case "吉林省" :
				areaCode = "长春";
				break;
			case "上海" :
				areaCode = "上海";
				break;
			case "宁夏省" :
				areaCode = "银川";
				break;
			case "湖南省" :
				areaCode = "长沙";
				break;
			case "安徽省" :
				areaCode = "合肥";
				break;
			case "青海省" :
				areaCode = "西宁";
				break;
			case "内蒙古" :
				areaCode = "呼和浩特";
				break;
			case "河北省" :
				areaCode = "石家庄";
				break;
			case "江西省" :
				areaCode = "南昌";
				break;
			case "辽宁省" :
				areaCode = "沈阳";
				break;
			case "广东省" :
				areaCode = "广州";
				break;
			case "福建省" :
				areaCode = "福州";
				break;
			case "广西省" :
				areaCode = "南宁";
				break;
			case "黑龙江省" :
				areaCode = "哈尔滨";
				break;
			case "海南省" :
				areaCode = "海口";
				break;
			case "云南省" :
				areaCode = "昆明";
				break;
			case "河南省" :
				areaCode = "郑州";
				break;
			case "浙江省" :
				areaCode = "杭州";
				break;
			case "山西省" :
				areaCode = "太原";
				break;
			case "山东省" :
				areaCode = "济南";
				break;
			case "西藏" :
				areaCode = "拉萨";
				break;
			case "新疆" :
				areaCode = "乌鲁木齐";
				break;
		}
		return areaCode;
	}
	public static String areaCode(String province) {
		String[] str = {"29","512","851","931","28","27","10","431","21","951","731","551","971","471","311","791","24","756","591","771","451","898","871","371","571","351"};
		Random random = new Random();
		int n = random.nextInt(str.length);
		String areaCode = str[n];
		switch (province) {
			case "陕西省" :
				areaCode = "29";
				break;
			case "江苏省" :
				areaCode = "512";
				break;
			case "贵州省" :
				areaCode = "851";
				break;
			case "甘肃省" :
				areaCode = "931";
				break;
			case "四川省" :
				areaCode = "28";
				break;
			case "湖北省" :
				areaCode = "27";
				break;
			case "北京" :
				areaCode = "10";
				break;
			case "吉林省" :
				areaCode = "431";
				break;
			case "上海" :
				areaCode = "21";
				break;
			case "宁夏省" :
				areaCode = "951";
				break;
			case "湖南省" :
				areaCode = "731";
				break;
			case "安徽省" :
				areaCode = "551";
				break;
			case "青海省" :
				areaCode = "971";
				break;
			case "内蒙古" :
				areaCode = "471";
				break;
			case "河北省" :
				areaCode = "311";
				break;
			case "江西省" :
				areaCode = "791";
				break;
			case "辽宁省" :
				areaCode = "24";
				break;
			case "广东省" :
				areaCode = "756";
				break;
			case "福建省" :
				areaCode = "591";
				break;
			case "广西省" :
				areaCode = "771";
				break;
			case "黑龙江省" :
				areaCode = "451";
				break;
			case "海南省" :
				areaCode = "898";
				break;
			case "云南省" :
				areaCode = "871";
				break;
			case "河南省" :
				areaCode = "371";
				break;
			case "浙江省" :
				areaCode = "571";
				break;
			case "山西省" :
				areaCode = "351";
				break;
		}
		return areaCode;
	}

	public static String provinceNum(String province){
		String areaCode = "99";
		switch (province) {
			case "陕西" :
				areaCode = "61";
				break;
			case "江苏" :
				areaCode = "32";
				break;
			case "贵州" :
				areaCode = "52";
				break;
			case "甘肃" :
				areaCode = "62";
				break;
			case "四川" :
				areaCode = "51";
				break;
			case "湖北" :
				areaCode = "42";
				break;
			case "北京" :
				areaCode = "11";
				break;
			case "吉林" :
				areaCode = "22";
				break;
			case "上海" :
				areaCode = "31";
				break;
			case "宁夏" :
				areaCode = "64";
				break;
			case "湖南" :
				areaCode = "43";
				break;
			case "安徽" :
				areaCode = "34";
				break;
			case "青海" :
				areaCode = "63";
				break;
			case "内蒙古" :
				areaCode = "15";
				break;
			case "河北" :
				areaCode = "13";
				break;
			case "江西" :
				areaCode = "36";
				break;
			case "辽宁" :
				areaCode = "21";
				break;
			case "广东" :
				areaCode = "44";
				break;
			case "福建" :
				areaCode = "35";
				break;
			case "广西" :
				areaCode = "45";
				break;
			case "黑龙江" :
				areaCode = "23";
				break;
			case "海南" :
				areaCode = "46";
				break;
			case "云南" :
				areaCode = "53";
				break;
			case "河南" :
				areaCode = "41";
				break;
			case "浙江" :
				areaCode = "33";
				break;
			case "山西" :
				areaCode = "14";
				break;
		}
		return areaCode;
	}

	//判断姓氏
	public static boolean ClearName(String name){
		String[] surName = {
				"赵","钱","孙","李","周","吴","郑","王","冯","陈",
				"楮","卫","蒋","沈","韩","杨","朱","秦","尤","许",
				"何","吕","施","张","孔","曹","严","华","金","魏",
				"陶","姜","戚","谢","邹","喻","柏","水","窦","章",
				"云","苏","潘","葛","奚","范","彭","郎","鲁","韦",
				"昌","马","苗","凤","花","方","俞","任","袁","柳",
				"酆","鲍","史","唐","费","廉","岑","薛","雷","贺",
				"倪","汤","滕","殷","罗","毕","郝","邬","安","常",
				"乐","于","时","傅","皮","卞","齐","康","伍","余",
				"元","卜","顾","孟","平","黄","和","穆","萧","尹",
				"姚","邵","湛","汪","祁","毛","禹","狄","米","贝",
				"明","臧","计","伏","成","戴","谈","宋","茅","庞",
				"熊","纪","舒","屈","项","祝","董","梁","杜","阮",
				"蓝","闽","席","季","麻","强","贾","路","娄","危",
				"江","童","颜","郭","梅","盛","林","刁","锺","徐",
				"丘","骆","高","夏","蔡","田","樊","胡","凌","霍",
				"虞","万","支","柯","昝","管","卢","莫","经","房",
				"裘","缪","干","解","应","宗","丁","宣","贲","邓",
				"郁","单","杭","洪","包","诸","左","石","崔","吉",
				"钮","龚","程","嵇","邢","滑","裴","陆","荣","翁",
				"荀","羊","於","惠","甄","麹","家","封","芮","羿",
				"储","靳","汲","邴","糜","松","井","段","富","巫",
				"乌","焦","巴","弓","牧","隗","山","谷","车","侯",
				"宓","蓬","全","郗","班","仰","秋","仲","伊","宫",
				"宁","仇","栾","暴","甘","斜","厉","戎","祖","武",
				"符","刘","景","詹","束","龙","叶","幸","司","韶",
				"郜","黎","蓟","薄","印","宿","白","怀","蒲","邰",
				"从","鄂","索","咸","籍","赖","卓","蔺","屠","蒙",
				"池","乔","阴","郁","胥","能","苍","双","闻","莘",
				"党","翟","谭","贡","劳","逄","姬","申","扶","堵",
				"冉","宰","郦","雍","郤","璩","桑","桂","濮","牛",
				"寿","通","边","扈","燕","冀","郏","浦","尚","农",
				"温","别","庄","晏","柴","瞿","阎","充","慕","连",
				"茹","习","宦","艾","鱼","容","向","古","易","慎",
				"戈","廖","庾","终","暨","居","衡","步","都","耿",
				"满","弘","匡","国","文","寇","广","禄","阙","东",
				"欧","殳","沃","利","蔚","越","夔","隆","师","巩",
				"厍","聂","晁","勾","敖","融","冷","訾","辛","阚",
				"那","简","饶","空","曾","毋","沙","乜","养","鞠",
				"须","丰","巢","关","蒯","相","查","后","荆","红",
				"游","竺","权","逑","盖","益","桓","公","仉","督",
				"晋","楚","阎","法","汝","鄢","涂","钦","归","海",
				"岳","帅","缑","亢","况","后","有","琴","商","牟",
				"佘","佴","伯","赏","墨","哈","谯","笪","年","爱",
				"阳","佟",
				"万俟","司马","上官","欧阳","夏侯",
				"诸葛","闻人","东方","赫连","皇甫",
				"尉迟","公羊","澹台","公冶","宗政",
				"濮阳","淳于","单于","太叔","申屠",
				"公孙","仲孙","轩辕","令狐","锺离",
				"宇文","长孙","慕容","鲜于","闾丘",
				"司徒","司空","丌官","司寇","南宫",
				"子车","颛孙","端木","巫马","公西",
				"漆雕","乐正","壤驷","公良","拓拔",
				"夹谷","宰父","谷梁","段干","百里",
				"东郭","南门","呼延","羊舌","微生",
				"梁丘","左丘","东门","西门"
		};

		String firstName = name.substring(0,1);
		for(String s : surName){
			String s1 = s.substring(0,1);
			if(s.contains(firstName)){
				return true;
			}
		}
		return false;
	}
	//手机号码靓号判断
	public static Integer isPhonePretty(String phone){
		//5A
		String aaaaa = "([\\d])\\1{4}";
		Matcher matcher2 = Pattern.compile(aaaaa).matcher(phone.substring(3, 11));
		if (matcher2.find()) {
			return 2;
		}
		//6A
		String aaaaaa = "([\\d])\\1{5}";
		Matcher matcher3 = Pattern.compile(aaaaaa).matcher(phone.substring(3, 11));
		if (matcher3.find()) {
			return 2;
		}
		//7A
		String aaaaaaa = "([\\d])\\1{6}";
		Matcher matcher4 = Pattern.compile(aaaaaaa).matcher(phone.substring(3, 11));
		if (matcher4.find()) {
			return 2;
		}
		//abcdef
		String abcdef = "(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){5}\\d";
		Matcher matcher5 = Pattern.compile(abcdef).matcher(phone.substring(3, 11));
		if (matcher5.find()) {
			return 2;
		}
		//ABBBCDDD
		String abbbcddd = "([\\d])\\1{0}([\\d])\\2{2}([\\d])\\3{0}([\\d])\\4{2}";
		Matcher matcher10 = Pattern.compile(abbbcddd).matcher(phone.substring(3, 11));
		if (matcher10.find()) {
			return 2;
		}
		//ABABCCCC
		String ababcccc = "(\\d)(\\d)\\1\\2([\\d])\\3{3}";
		Matcher matcher11 = Pattern.compile(ababcccc).matcher(phone.substring(3, 11));
		if (matcher11.find()) {
			return 2;
		}
		//ABABABAB
		String abababab = "([\\d])([\\d])\\1\\2{1}([\\d])([\\d])\\3\\4{1}";
		Matcher matcher12 = Pattern.compile(abababab).matcher(phone.substring(3, 11));
		if (matcher12.find()) {
			return 2;
		}
		//AAABAAAB
		String aaabaaab = "([\\d])\\1{2}([\\d])\\2{0}([\\d])\\3{2}([\\d])\\4{0}";
		Matcher matcher13 = Pattern.compile(aaabaaab).matcher(phone.substring(3, 11));
		if (matcher13.find()) {
			return 2;
		}
		//ABCABC
		String abcabc = "^(\\d)(\\d)(\\d)\\1\\2\\3$";
		Pattern pattern = Pattern.compile(abcabc);
		Matcher matcher = pattern.matcher(phone.substring(5,11));
		if (matcher.find()) {
			return 1;
		}
		//AAA
		String aaa = "([\\d])\\1{2}";
		Matcher matcher1 = Pattern.compile(aaa).matcher(phone.substring(8,11));
		if (matcher1.find()) {
			return 1;
		}
		//AAAA
		String aaaa = "([\\d])\\1{3}";
		Matcher matcher9 = Pattern.compile(aaaa).matcher(phone.substring(3,11));
		if (matcher9.find()) {
			return 1;
		}
		//AABB
		String aabb = "(\\d)\\1{1}((?!\\1)\\d)\\2{1}";
		Matcher matcher6 = Pattern.compile(aabb).matcher(phone.substring(8, 11));
		if (matcher6.find()) {
			return 1;
		}
		//abcd
		String abcd = "(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){3}\\d";
		Matcher matcher7 = Pattern.compile(abcd).matcher(phone.substring(7, 11));
		if (matcher7.find()) {
			return 1;
		}
		//abcde
		String abcde = "(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){4}\\d";
		Matcher matcher8 = Pattern.compile(abcde).matcher(phone.substring(6, 11));
		if (matcher8.find()) {
			return 1;
		}
		return 0;
	}

	private static final String PHONE_ALL = "^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$";

	/**
	 * @function 检测该字符串是否包含手机号
	 * @author zhaoxutao
	 * @date 2019年8月19日 11:10
	 * @param str
	 * @return boolean true：包含，false：无
	 * @version 2.0.2
	 */
	public static boolean checkIncludePhone(String str) {
		if (StringUtils.isNotBlank(str)) {
			return false;
		}
		return (boolean) checkNickName(str,1);
	}

	/**
	 * @function 获取该字符串中的手机号
	 * @author zhaoxutao
	 * @date 2019年8月19日 11:10
	 * @annotation 该方法返回多个手机号
	 * @param str
	 * @return String 返回手机号
	 * @version 2.0.2
	 */
	@SuppressWarnings("unchecked")
	public static List<String> checkGetPhone(String str) {
		if (!StringUtils.isNotBlank(str)) {
			return null;
		}
		return (List<String>) checkNickName(str,2);
	}

	/**
	 * 检查昵称是否包括手机号
	 * @param nickName 校验字符 type 1:返回Boolean 2：返回手机号
	 * @return 包括:true：null
	 */
	private static Object checkNickName(String nickName,int type) {
		// 过滤出纯数字
		nickName = Pattern.compile("[^0-9]").matcher(nickName.trim()).replaceAll("");
		List<String> list = new ArrayList<String>();
		if (nickName.length() < 11) {
			return type==1?false:list;
		}
		char[] chars = nickName.toCharArray();
		ArrayList<String> phoneList = new ArrayList<>();//所有11位数字的集合
		for(int i = 0; i < chars.length; i++){
			StringBuilder stringBuilder = new StringBuilder();
			for(int j = 0; j < 11; j++){
				if(i + j < chars.length){
					stringBuilder.append(chars[i + j]);
				}
			}
			if(stringBuilder.length()==11){
				phoneList.add(stringBuilder.toString());
			}
		}
		List<String> regexList = new ArrayList<String>();

		regexList.add(PHONE_ALL);
		for(String phone : phoneList){
			for (String regex : regexList) {
				Pattern pattern = Pattern.compile(regex);
				Matcher matcher = pattern.matcher(phone);
				if (matcher.matches()) {
					if (type == 1) {
						return true;
					} else {
						list.add(phone);
					}
				}
			}
		}
		return type==1?false:new ArrayList<>(new HashSet<>(list));
	}
}
